{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 首先 import 必要的模块\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pregnants</th>\n",
       "      <th>Plasma_glucose_concentration</th>\n",
       "      <th>blood_pressure</th>\n",
       "      <th>Triceps_skin_fold_thickness</th>\n",
       "      <th>serum_insulin</th>\n",
       "      <th>BMI</th>\n",
       "      <th>Diabetes_pedigree_function</th>\n",
       "      <th>Age</th>\n",
       "      <th>Target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.639947</td>\n",
       "      <td>0.866045</td>\n",
       "      <td>-0.031990</td>\n",
       "      <td>0.670643</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>0.166619</td>\n",
       "      <td>0.468492</td>\n",
       "      <td>1.425995</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.844885</td>\n",
       "      <td>-1.205066</td>\n",
       "      <td>-0.528319</td>\n",
       "      <td>-0.012301</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>-0.852200</td>\n",
       "      <td>-0.365061</td>\n",
       "      <td>-0.190672</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.233880</td>\n",
       "      <td>2.016662</td>\n",
       "      <td>-0.693761</td>\n",
       "      <td>-0.012301</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>-1.332500</td>\n",
       "      <td>0.604397</td>\n",
       "      <td>-0.105584</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.844885</td>\n",
       "      <td>-1.073567</td>\n",
       "      <td>-0.528319</td>\n",
       "      <td>-0.695245</td>\n",
       "      <td>-0.540642</td>\n",
       "      <td>-0.633881</td>\n",
       "      <td>-0.920763</td>\n",
       "      <td>-1.041549</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-1.141852</td>\n",
       "      <td>0.504422</td>\n",
       "      <td>-2.679076</td>\n",
       "      <td>0.670643</td>\n",
       "      <td>0.316566</td>\n",
       "      <td>1.549303</td>\n",
       "      <td>5.484909</td>\n",
       "      <td>-0.020496</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   pregnants  Plasma_glucose_concentration  blood_pressure  \\\n",
       "0   0.639947                      0.866045       -0.031990   \n",
       "1  -0.844885                     -1.205066       -0.528319   \n",
       "2   1.233880                      2.016662       -0.693761   \n",
       "3  -0.844885                     -1.073567       -0.528319   \n",
       "4  -1.141852                      0.504422       -2.679076   \n",
       "\n",
       "   Triceps_skin_fold_thickness  serum_insulin       BMI  \\\n",
       "0                     0.670643      -0.181541  0.166619   \n",
       "1                    -0.012301      -0.181541 -0.852200   \n",
       "2                    -0.012301      -0.181541 -1.332500   \n",
       "3                    -0.695245      -0.540642 -0.633881   \n",
       "4                     0.670643       0.316566  1.549303   \n",
       "\n",
       "   Diabetes_pedigree_function       Age  Target  \n",
       "0                    0.468492  1.425995       1  \n",
       "1                   -0.365061 -0.190672       0  \n",
       "2                    0.604397 -0.105584       1  \n",
       "3                   -0.920763 -1.041549       0  \n",
       "4                    5.484909 -0.020496       1  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#input data\n",
    "train = pd.read_csv(\"FE_pima-indians-diabetes.csv\")\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pregnants</th>\n",
       "      <th>Plasma_glucose_concentration</th>\n",
       "      <th>blood_pressure</th>\n",
       "      <th>Triceps_skin_fold_thickness</th>\n",
       "      <th>serum_insulin</th>\n",
       "      <th>BMI</th>\n",
       "      <th>Diabetes_pedigree_function</th>\n",
       "      <th>Age</th>\n",
       "      <th>Target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>7.680000e+02</td>\n",
       "      <td>768.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>2.544261e-17</td>\n",
       "      <td>1.474515e-17</td>\n",
       "      <td>-3.321273e-17</td>\n",
       "      <td>-1.888680e-16</td>\n",
       "      <td>2.941802e-17</td>\n",
       "      <td>2.815312e-16</td>\n",
       "      <td>2.422108e-16</td>\n",
       "      <td>1.528002e-16</td>\n",
       "      <td>0.348958</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>1.000652e+00</td>\n",
       "      <td>0.476951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-1.141852e+00</td>\n",
       "      <td>-2.552931e+00</td>\n",
       "      <td>-4.002619e+00</td>\n",
       "      <td>-2.516429e+00</td>\n",
       "      <td>-1.467353e+00</td>\n",
       "      <td>-2.074783e+00</td>\n",
       "      <td>-1.189553e+00</td>\n",
       "      <td>-1.041549e+00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-8.448851e-01</td>\n",
       "      <td>-7.201630e-01</td>\n",
       "      <td>-6.937615e-01</td>\n",
       "      <td>-4.675972e-01</td>\n",
       "      <td>-2.220849e-01</td>\n",
       "      <td>-7.212087e-01</td>\n",
       "      <td>-6.889685e-01</td>\n",
       "      <td>-7.862862e-01</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>-2.509521e-01</td>\n",
       "      <td>-1.530732e-01</td>\n",
       "      <td>-3.198993e-02</td>\n",
       "      <td>-1.230129e-02</td>\n",
       "      <td>-1.815412e-01</td>\n",
       "      <td>-2.258989e-02</td>\n",
       "      <td>-3.001282e-01</td>\n",
       "      <td>-3.608474e-01</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>6.399473e-01</td>\n",
       "      <td>6.112653e-01</td>\n",
       "      <td>6.297816e-01</td>\n",
       "      <td>3.291706e-01</td>\n",
       "      <td>-1.554775e-01</td>\n",
       "      <td>6.032562e-01</td>\n",
       "      <td>4.662269e-01</td>\n",
       "      <td>6.602056e-01</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>3.906578e+00</td>\n",
       "      <td>2.542658e+00</td>\n",
       "      <td>4.104082e+00</td>\n",
       "      <td>7.955377e+00</td>\n",
       "      <td>8.170442e+00</td>\n",
       "      <td>5.042397e+00</td>\n",
       "      <td>5.883565e+00</td>\n",
       "      <td>4.063716e+00</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          pregnants  Plasma_glucose_concentration  blood_pressure  \\\n",
       "count  7.680000e+02                  7.680000e+02    7.680000e+02   \n",
       "mean   2.544261e-17                  1.474515e-17   -3.321273e-17   \n",
       "std    1.000652e+00                  1.000652e+00    1.000652e+00   \n",
       "min   -1.141852e+00                 -2.552931e+00   -4.002619e+00   \n",
       "25%   -8.448851e-01                 -7.201630e-01   -6.937615e-01   \n",
       "50%   -2.509521e-01                 -1.530732e-01   -3.198993e-02   \n",
       "75%    6.399473e-01                  6.112653e-01    6.297816e-01   \n",
       "max    3.906578e+00                  2.542658e+00    4.104082e+00   \n",
       "\n",
       "       Triceps_skin_fold_thickness  serum_insulin           BMI  \\\n",
       "count                 7.680000e+02   7.680000e+02  7.680000e+02   \n",
       "mean                 -1.888680e-16   2.941802e-17  2.815312e-16   \n",
       "std                   1.000652e+00   1.000652e+00  1.000652e+00   \n",
       "min                  -2.516429e+00  -1.467353e+00 -2.074783e+00   \n",
       "25%                  -4.675972e-01  -2.220849e-01 -7.212087e-01   \n",
       "50%                  -1.230129e-02  -1.815412e-01 -2.258989e-02   \n",
       "75%                   3.291706e-01  -1.554775e-01  6.032562e-01   \n",
       "max                   7.955377e+00   8.170442e+00  5.042397e+00   \n",
       "\n",
       "       Diabetes_pedigree_function           Age      Target  \n",
       "count                7.680000e+02  7.680000e+02  768.000000  \n",
       "mean                 2.422108e-16  1.528002e-16    0.348958  \n",
       "std                  1.000652e+00  1.000652e+00    0.476951  \n",
       "min                 -1.189553e+00 -1.041549e+00    0.000000  \n",
       "25%                 -6.889685e-01 -7.862862e-01    0.000000  \n",
       "50%                 -3.001282e-01 -3.608474e-01    0.000000  \n",
       "75%                  4.662269e-01  6.602056e-01    1.000000  \n",
       "max                  5.883565e+00  4.063716e+00    1.000000  "
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查看数值型特征的基本统计量\n",
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train = train['Target']   \n",
    "X_train = train.drop([\"Target\"], axis=1)\n",
    "\n",
    "#保存特征名字以备后用（可视化）\n",
    "feat_names = X_train.columns "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "liblinear_lr best_score= 0.47602528511413894\n",
      "liblinear_lr best_params= {'C': 1, 'penalty': 'l1'}\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "penaltys = ['l1','l2']\n",
    "Cs = [ 0.01,0.1, 1, 10, 100, 1000,10000]\n",
    "tuned_parameters = dict(penalty = penaltys, C = Cs)\n",
    "\n",
    "liblinear_lr= LogisticRegression(solver='liblinear')\n",
    "grid= GridSearchCV(liblinear_lr, tuned_parameters,cv=5, scoring='neg_log_loss',n_jobs = 4,)\n",
    "grid.fit(X_train,y_train)\n",
    "print('liblinear_lr best_score=',-grid.best_score_)\n",
    "print('liblinear_lr best_params=',grid.best_params_)\n",
    "liblinear_lr_best_estimator_grid=grid.best_estimator_ #solver='liblinear',cv=5, scoring='neg_log_loss'时网格搜索到的最优模型：C=1, penalty=l1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saga_lr_lr best_score= 0.47602066684192046\n",
      "saga_lr_lr best_params= {'C': 1, 'penalty': 'l1'}\n"
     ]
    }
   ],
   "source": [
    "saga_lr= LogisticRegression(solver='saga')\n",
    "grid= GridSearchCV(saga_lr, tuned_parameters,cv=5, scoring='neg_log_loss',n_jobs = 4,)\n",
    "grid.fit(X_train,y_train)\n",
    "print('saga_lr_lr best_score=',-grid.best_score_)\n",
    "print('saga_lr_lr best_params=',grid.best_params_)\n",
    "saga_lr_lr_best_estimator_grid=grid.best_estimator_#solver='saga',cv=5, scoring='neg_log_loss'时网格搜索到的最优模型：C=1, penalty=l1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过网格搜索可知，最合理的惩罚函数为L1，优化器为liblinear，最优交叉熵损失函数系数应该在1附近"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "scores= 0.4803881599382852\n",
      "C= [0.2]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegressionCV\n",
    "\n",
    "Cs = [ 0.04, 0.2, 1, 5, 25]\n",
    "lr_cv= LogisticRegressionCV(Cs=Cs,cv=5,penalty='l1',scoring='neg_log_loss',solver='liblinear')\n",
    "lr_cv.fit(X_train,y_train)\n",
    "print('scores=',-lr_cv.scores_[1].mean())\n",
    "print('C=',lr_cv.C_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过5折逻辑回归校验，C搜索范围缩小至1附近后，发现分数有提升进一步，最优交叉熵损失函数系数可能在0.2附近"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "scores= 0.4831594409292607\n",
      "C= [0.5]\n"
     ]
    }
   ],
   "source": [
    "Cs = [ 0.032, 0.08, 0.2, 0.5, 1.25]\n",
    "lr_cv= LogisticRegressionCV(Cs=Cs,cv=5,penalty='l1',scoring='neg_log_loss',solver='liblinear')\n",
    "lr_cv.fit(X_train,y_train)\n",
    "print('scores=',-lr_cv.scores_[1].mean())\n",
    "print('C=',lr_cv.C_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.5811388300841898 [0.12649110640673517, 0.2, 0.316227766016838, 0.5, 0.7905694150420949]\n",
      "scores= 0.4759462596261315\n",
      "C= [0.31622777]\n"
     ]
    }
   ],
   "source": [
    "#最优交叉熵损失函数系数可能在0.2和0.5之间\n",
    "d=(0.5/0.2)**0.5\n",
    "Cs = [ 0.2/d, 0.2, 0.2*d, 0.5, 0.5*d]\n",
    "print(d,Cs)\n",
    "lr_cv= LogisticRegressionCV(Cs=Cs,cv=5,penalty='l1',scoring='neg_log_loss',solver='liblinear')\n",
    "lr_cv.fit(X_train,y_train)\n",
    "print('scores=',-lr_cv.scores_[1].mean())\n",
    "print('C=',lr_cv.C_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Cs=[0.5,0.2,1,0.31622777]，得分最高的C=0.5(scores= 0.4831590595663245)，所以最优的Logistic回归模型的正则超参数C为0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当penalty='l1',C=0.5,solver='liblinear'时，accuracy_score= 0.7792207792207793 ,log_loss= 7.625485676664965\n"
     ]
    }
   ],
   "source": [
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import accuracy_score\n",
    "from sklearn.metrics import log_loss\n",
    "\n",
    "# 随机采样10%的数据构建测试样本\n",
    "X_train, X_test, y_train, y_true = train_test_split(X_train, y_train, random_state=123, test_size=0.1)\n",
    "\n",
    "lr= LogisticRegression(penalty='l1',C=0.5,solver='liblinear').fit(X_train, y_train)\n",
    "y_pred=lr.predict(X_test)\n",
    "\n",
    "accuracy_score_my=accuracy_score(y_true, y_pred)\n",
    "log_loss_my=log_loss(y_true, y_pred)\n",
    "print(\"当penalty='l1',C=0.5,solver='liblinear'时，accuracy_score=\",accuracy_score_my,\",log_loss=\",log_loss_my)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n",
       "          penalty='l1', random_state=None, solver='liblinear', tol=0.0001,\n",
       "          verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liblinear_lr_best_estimator_grid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当penalty='l1',C=1,solver='liblinear'时，accuracy_score= 0.7922077922077922 ,log_loss= 7.176930139068723\n"
     ]
    }
   ],
   "source": [
    "y_pred=liblinear_lr_best_estimator_grid.predict(X_test)\n",
    "accuracy_score_1=accuracy_score(y_true, y_pred)\n",
    "log_loss_1=log_loss(y_true, y_pred)\n",
    "print(\"当penalty='l1',C=1,solver='liblinear'时，accuracy_score=\",accuracy_score_1,\",log_loss=\",log_loss_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n",
       "          penalty='l1', random_state=None, solver='saga', tol=0.0001,\n",
       "          verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "saga_lr_lr_best_estimator_grid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当penalty='l1',C=1,solver='saga'时，accuracy_score= 0.7922077922077922 ,log_loss= 7.176930139068723\n"
     ]
    }
   ],
   "source": [
    "y_pred=saga_lr_lr_best_estimator_grid.predict(X_test)\n",
    "accuracy_score_2=accuracy_score(y_true, y_pred)\n",
    "log_loss_2=log_loss(y_true, y_pred)\n",
    "print(\"当penalty='l1',C=1,solver='saga'时，accuracy_score=\",accuracy_score_2,\",log_loss=\",log_loss_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "发现：当其他参数相同时，solver不影响模型评分，如：solver='saga'或'liblinear'时，accuracy_score= 0.7922077922077922 ,log_loss= 7.176930139068723"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "结论：用GridSearchCV自动查找的模型参数C=1，比自己手动调的C=0.5，性能更高：最佳得分为accuracy_score= 0.7922077922077922 ,log_loss= 7.176930139068723"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在已找到C=1的最佳正则超参数提前下，系数为："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "accuracy_score= 0.7792207792207793 ,log_loss= 7.625485676664965\n",
      "coef_:\n",
      " [[ 0.33210779  1.08889415 -0.05692124  0.0548324  -0.09840344  0.56952023\n",
      "   0.30708682  0.20024   ]]\n"
     ]
    }
   ],
   "source": [
    "lr= LogisticRegression(penalty='l1',tol=0.00000001,C=1,random_state=456).fit(X_train, y_train)\n",
    "y_pred=lr.predict(X_test)\n",
    "accuracyScore=accuracy_score(y_true, y_pred)\n",
    "logLoss=log_loss(y_true, y_pred)\n",
    "print(\"accuracy_score=\",accuracyScore,\",log_loss=\",logLoss)\n",
    "print('coef_:\\n',lr.coef_)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
